package io.comiccloud.rest

import akka.http.scaladsl.model.StatusCodes._
import akka.http.scaladsl.server._
import io.comiccloud.models.Account
import scalaoauth2.provider._

trait OAuthRoutes extends DefaultSupport with OAuth2RouteProvider[Account] {
  override val oauth2DataHandler = new MyDataHandler()

  def protectedRoute: Route = path("resources") {
    get {
      authenticateOAuth2Async[AuthInfo[Account]]("realm", oauth2Authenticator) {
        auth => complete(OK, auth)
      }
    }
  }

  val routes: Route = accessTokenRoute ~ protectedRoute

}